<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2023 yoncron All rights reserved.
// +----------------------------------------------------------------------
// | Author: yoncron <yoncron@163.com>
// +----------------------------------------------------------------------

ini_set('memory_limit', '512M');

function input($key, $default = null)
{
    return request()->input($key, $default);
}

function rawBody()
{
    return request()->rawBody();
}

function success($data = null, $code = 0, $msg = "success",$options = JSON_UNESCAPED_UNICODE)
{
    $_data['code'] = $code;
    $_data['msg'] = $msg;
    if (isset($data)) {
        $_data['data'] = $data;
    }
    return json($_data,$options);
}

function error($code = 1, $msg = "unknown error")
{
    $_data['code'] = $code;
    $_data['msg'] = $msg;
    return json($_data);
}

function object_array($array)
{
    if (is_object($array)) {
        $array = (array)$array;
    }
    if (is_array($array)) {
        foreach ($array as $key => $value) {
            $array[$key] = object_array($value);
        }
    }
    return $array;
}